<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace IdenApi\Api;
use IdenApi\Http\HttpRequest;
use IdenApi\Constant\HttpMethod;
use IdenApi\Constant\HttpHeader;
use IdenApi\Constant\ContentType;
use IdenApi\Constant\SystemHeader;
use IdenApi\Http\HttpClient;





class IndexApi{

    private static $appKey = "24751147";
    private static $appSecret = "35924736f6040933e35aa95e3e82723d";
    //协议(http或https)://域名:端口，注意必须有http://或https://
    private static $host = "http://idcard.market.alicloudapi.com";

    /**
    *method=GET请求示例
    */
    public function doGet($cardno,$name) {

        // var_dump(3);exit;
       
        // var_dump($cardno);
        // var_dump($name);exit;

        //域名后、query前的部分
        $path = "/lianzhuo/idcard";

        $method = new HttpMethod();

        $request = new HttpRequest($this::$host, $path, $method::GET, $this::$appKey, $this::$appSecret);

        //设定Content-Type，根据服务器端接受的值来设置
        $request->setHeader(HttpHeader::HTTP_HEADER_CONTENT_TYPE, ContentType::CONTENT_TYPE_TEXT);
        
        //设定Accept，根据服务器端接受的值来设置
        $request->setHeader(HttpHeader::HTTP_HEADER_ACCEPT, ContentType::CONTENT_TYPE_JSON);
        //如果是调用测试环境请设置
        //$request->setHeader(SystemHeader::X_CA_STAG, "TEST");


        //注意：业务header部分，如果没有则无此行(如果有中文，请做Utf8ToIso88591处理)
        //mb_convert_encoding("headervalue2中文", "ISO-8859-1", "UTF-8");
        // $request->setHeader("b-header2", "headervalue2");
        // $request->setHeader("a-header1", "headervalue1");

        //注意：业务query部分，如果没有则无此行；请不要、不要、不要做UrlEncode处理
        // $request->setQuery("cardno", "370703198111300338");
        // $request->setQuery("name", "郭德昌");

        $request->setQuery("cardno", $cardno);
        $request->setQuery("name", $name);

        //指定参与签名的header
        $request->setSignHeader(SystemHeader::X_CA_TIMESTAMP);
        $request->setSignHeader("X-Ca-Request-Mode");
        $request->setSignHeader("X-Ca-Version");
        $request->setSignHeader("X-Ca-Stage");
        $request->setSignHeader("X-Ca-Key");

        $response = HttpClient::execute($request);
        // print_r(json_decode($response));
        // print_r($request);

        // print_r($response);
        return $response;

    }
}
